package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.center.bean.ExceptionReviseBean;
import com.ms.square.android.expandabletextview.ExpandableTextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ExceptionReviseAdapter extends BaseRecycleListAdapter<ExceptionReviseBean> {

    ClickListenrer clickListenrer;

    List<ExceptionReviseBean> mList;

    public ExceptionReviseAdapter(List<ExceptionReviseBean> mList, Context context ,  ClickListenrer clickListenrer) {
        super(mList, context);
        this.mList = mList;
        this.clickListenrer = clickListenrer;
    }

    public void setmList(List<ExceptionReviseBean> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @Override
    public int getLayoutId() {
        return R.layout.exception_revise_item;
    }

    @Override
    public RecyclerView.ViewHolder createHolder(View view) {
        return new ViewHolder(view);
    }


    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, ExceptionReviseBean bean, int position) {
        if(holder instanceof ViewHolder){
            ((ViewHolder) holder).setData(bean , position);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_time1)
        TextView tvTime1;
        @Bind(R.id.iv_null1)
        ImageView ivNull1;
        @Bind(R.id.tv_time2)
        TextView tvTime2;
        @Bind(R.id.iv_null2)
        ImageView ivNull2;
        @Bind(R.id.tv_year)
        TextView tvYear;
        @Bind(R.id.tv_number)
        TextView tvNumber;
        @Bind(R.id.expandable_text)
        TextView expandableText;
        @Bind(R.id.expand_collapse)
        ImageButton expandCollapse;
        @Bind(R.id.expand_text_view)
        ExpandableTextView expandTextView;
        @Bind(R.id.ll_revise)
        LinearLayout llRevise;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void setData(final ExceptionReviseBean bean , final int position) {

            tvName.setText(bean.getXname());
            tvYear.setText(bean.getQDtime());
            tvNumber.setText("未打卡次数："+ bean.getWeiChiS());
            expandTextView.setText("异常情况说明："+ bean.getQKSM()) ;
            String zaoShangQD = bean.getZaoShangQD();
            if(TextUtils.isEmpty(zaoShangQD)){
                tvTime1.setText("");
                ivNull1.setVisibility(View.VISIBLE);
                tvTime1.setVisibility(View.GONE);
            } else {
                tvTime1.setText(zaoShangQD);
                ivNull1.setVisibility(View.GONE);
            }

            String xiWuQD = bean.getXiWuQD();
            if(TextUtils.isEmpty(xiWuQD)) {
                tvTime2.setText("");
                ivNull2.setVisibility(View.VISIBLE);
                tvTime2.setVisibility(View.GONE);
            } else {
                tvTime2.setText(xiWuQD);
                ivNull2.setVisibility(View.GONE);
            }


            llRevise.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    clickListenrer.click(position , bean);
                }
            });

        }
    }

    public interface ClickListenrer{
        public void click(int index , ExceptionReviseBean bean);
    }

}
